<?php

namespace App\Models\Biz;

use Illuminate\Database\Eloquent\Model;
use Laracasts\Presenter\PresentableTrait;

class Coupon extends Model  
{
	//use PresentableTrait; 

	protected $table = 'biz_coupons';

	//protected $presenter = 'App\Http\Presenters\Biz\ItemPresenter';

	protected $guarded = array();

	public function belongsWho()
	{
		switch($this->scope)
		{
			case COUPON_SCOPE_2:
				return $this->belongsTo('\App\Models\Biz\Shop');
				break;
			case COUPON_SCOPE_3:
				return $this->belongsTo('\App\Models\Mgt\Category',category_id,id);
				break;
			case COUPON_SCOPE_4:
				return $this->belongsTo('\App\Models\Sku\Product');
				break;
			default:
				break;
		}
	}


	public function scopeCurrent($query, $staff)
    {
    	$supervisor = \Config::get('auth.supervisor');

    	if (!in_array($staff->id, $supervisor)){
    		return $query->where('branch_id', $staff->branch_id);
    	}
    }
}